package com.huilian.iotbox.admin.wap.controller;

import com.huilian.iotbox.admin.wap.service.PermissionGroupItemService;
import com.huilian.iotbox.data.common.ServerResponse;
import com.huilian.iotbox.data.dto.PermissionGroupItemDto;
import com.huilian.iotbox.data.vo.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author LinYinDong
 * @date 2024/10/29 下午4:01
 */
@Slf4j
@RestController
@RequestMapping("/api/permissionGroupItem")
public class PermissionGroupItemController extends UserInfoController {
    @Resource
    private PermissionGroupItemService permissionGroupItemService;
    @PostMapping("/findByPermissionGroupIdList")
    public ServerResponse findByPermissionGroupIdList(@RequestBody PermissionGroupItemDto permissionGroupItemDto, HttpServletRequest request) {
        try {
            UserInfo userInfo = super.getLoginUserInfo(request);
            permissionGroupItemDto.setUserInfo(userInfo);
            return permissionGroupItemService.findByPermissionGroupId(permissionGroupItemDto);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("商家端菜单查询失败，" + e.getMessage() + "接口：permissionGroupItemService.findByPermissionGroupIdList，参数：" + permissionGroupItemDto);
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }
}
